package com.smartplatform.task;

import com.smartplatform.event.CheckOnlineEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author 咕唧
 * @Date 2022/6/4 21:55
 * @Version 1.0
 */
@Component
@EnableScheduling//开启任务调度
public class CheckOnlineTask {
    private ApplicationContext context;

    @Autowired
    public void setContext(ApplicationContext context) {
        this.context = context;
    }

    @Scheduled(cron = "0/20 * * * * ?")
    public void checkOnline() {
        System.err.println("CheckOnlineTask的checkOnline方法执行了");
        context.publishEvent(new CheckOnlineEvent());
    }
}
